const app = getApp();
const {
  http
} = require("../../../utils/apiutils")
const
  util = require("../../../utils/util")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showpage:false,
    statusBar: 0,
    CustomBar: 0,
    userInfo: {},
    sum: {
      nviteSalarySum: 0,
      salarySum: 0,
      workSalarySum: 0
    },
    isLogin: false,
    showp:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let CustomBar = app.globalData.CustomBar;
    let statusBar = app.globalData.statusBar
    this.setData({
      CustomBar: CustomBar - statusBar,
      statusBar: statusBar,
      isLogin:getApp().globalData.isLogin,
      showp:getApp().globalData.showpage
    })

    console.log("-------------", this.data.userInfo);
  },

  onlogon: function () {
    console.log('isLogin',getApp().globalData.isLogin)
    if (!getApp().globalData.isLogin) {
      wx.showModal({
        title: "提示",
        content: "您还没有登录，登陆后即可享受更多服务",
        confirmText: "去登陆",
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/login/login?ptype=me',
            })
          }
        }
      })
      return;
    }
  },
  onclickCell: function (e) {
    if (!getApp().globalData.isLogin) {
      wx.showModal({
        title: "提示",
        content: "您还没有登录，登陆后即可享受更多服务",
        confirmText: "去登陆",
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/login/login?ptype=me',
            })
          }
        }
      })
      return;
    }
    let index = e.currentTarget.dataset.index;
    let url="";
    switch(index){
      case '1':
        url= '/pages/me/pages/profit/profit';
        break;
      case '2':
        url= '/pages/me/pages/follow/follow';
        break;
      case '3':
        url= '/pages/me/pages/recommend/recommend';
        break;
      case '4':
        url= '/pages/me/pages/bond/bond';
        break;
      case '5':
        url= '/pages/me/pages/security/security';
        break;
      case '11':
        url= '/pages/me/pages/nickname/nickname';
        break;
      case '21':
        url= '/pages/me/pages/action/action?type=1';
        break;
      case '22':
        url= '/pages/me/pages/action/action?type=2';
        break;
      case '23':
        url= '/pages/me/pages/action/action?type=3';
        break;
      case '24':
        url= '/pages/me/pages/action1/index';
        break;
      case '6':
        url= '/pages/me/pages/sharecompany/index';
        break;
      case 'jhsz':
        url= '/pages/me/pages/workSet/index';
        break;
      case 'zh':
        url= '/pages/me/pages/account/account';
        break;
      case 'rck':
        url= '/pages/clock/pages/rencai/index';
        break;
      case 'renwu':
        url= '/pages/me/pages/renwu/index';
        break;
	  case 'yj':
		url= '/pages/me/pages/yajin/index';
		break;
    }
      wx.navigateTo({
        url: url,
      })
    // console.log("-----------", e);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      isLogin: app.globalData.isLogin,
      showpage:getApp().globalData.showpage
    })
    if (app.globalData.isLogin) {
      this.getsalarySum()
      this.setData({
        userInfo: app.globalData.userInfo,
      })
    }

  },
  getsalarySum: function () {

    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.getsalarySum({},
      function (res) {
        wx.hideLoading()
        console.log("------总是收益--", res.data);
        if (res.code == 0) {
          that.setData({
            sum: res.data
          })
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })




  },

  /**上传图片 */
  onclickSelect: function () {
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        let imgSrc = res.tempFilePaths[0];
        that.uploadImage(imgSrc);
        console.log("------", res);
      },
    })
  },
  /**上传图片 */
  uploadImage: function (scr) {
    var data = {
      url: scr,
      name: "avatar",
      formData: {},
    }
    var that = this;
    wx.showLoading({
      title: '上传种...',
    })
    http.upavatar(data,
      function (res) {
        wx.hideLoading()
        console.log("------上传头像---", res);
        if (res.code == 0) {
          wx.showToast({
            title: "上传成功",
            icon: "none",
          })
          that.getuser();
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })
  },
  //获取用户信息
  getuser: function () {

    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.userInfo({},
      function (res) {
        wx.hideLoading()
        console.log("------用户信息--", res);
        if (res.code == 0) {
          getApp().globalData.userInfo = res.data;
          that.setData({
            userInfo: res.data
          })

        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var shareObj = {
      title: "分享岗位", // 默认是小程序的名称(可以写slogan等)
      path: getApp().globalData.userInfo.inviteCode?'/pages/index/index?code='+getApp().globalData.userInfo.inviteCode:'/pages/index/index', // 
      imageUrl: '',
      success: function (res) {
        // 转发成功之后的回调
        if (res.errMsg == 'shareAppMessage:ok') {
        }
      }
    }
    console.log("------------", shareObj);
    // 返回shareObj
    return shareObj;
  }
})